package tichu_project252.View.Player;

import java.awt.GridLayout;
import javax.swing.JPanel;
import tichu_project252.Model.Model;

/**
 *
 * This class implements the player buttons that implement the play, play bomb
 * and pass functions.
 *
 *
 * @author Alexandra Barka, ΑΜ: 2867, login : barka.
 * @version %I%, %G%
 */
public class controlButtons extends JPanel {

    private playCardsButton play = null;
    private passButton pass = null;
    private playBomb bomb = null;
    private Model m = null;
    private int player;

    /**
     * Constructs the Jpanel contains the three Buttons, player has.
     *
     * < p><b>Constructor: </b> controlButtons(Model m, int player) </p>
     *
     * <p><b>Precondition: </b> </p> <p><b>Postcondition: </b> Constructs a new
     * JPanel </p>
     *
     * @param m The model
     * @param player The player pushed the button
     */
    public controlButtons(Model m, int player) {
        super();
        
        play = new playCardsButton(m); // create the play button
        pass = new passButton(m, player); //create the pass button
        bomb = new playBomb(m, player); //create the bomb button
        
        this.player = player;
        this.m = m;
        this.setLayout(new GridLayout(3, 1)); //sets the layout of the buttons


        
        if (m.getPlayer(player).hasMahjong()) {
            play.setEnabled(true);
            pass.setEnabled(true);
        } else {
            
            play.setEnabled(false);
            pass.setEnabled(false);
        }

        this.add(play);
        this.add(pass);
        this.add(bomb);
    }

    /**
     * Sets if the buttton are enabled or not.
     * 
     * Transformer.
     * @param flag 
     */
    @Override
    public void setEnabled(boolean flag) {
        play.setEnabled(flag);
        pass.setEnabled(flag);
    }
    
    /**
     * Sets if the player has bomb or not.
     * 
     * Transformer.
     * @param player 
     */
    
    public void setBomb(int player) {
        bomb.setEnabled(false);
        
        if (m.getPlayer(player).hasBomb() == true || m.getPlayer(player).hasStreetBomb() == true) {
            bomb.setEnabled(true);
        }
    }
}
